from datetime import datetime

from sqlalchemy import Column, Integer, String, Boolean, Float, ForeignKey, UniqueConstraint, Index, orm, DECIMAL
from sqlalchemy.dialects.mysql import LONGTEXT

from app.libs.tools import number2string
from app.models.base import Base, db


class aigc_order_info(Base):
    id = Column(Integer, autoincrement=True, primary_key=True)
    order_number = Column(String(30), nullable=False, default='')
    title = Column(String(100), nullable=False, default='')
    author = Column(String(50), nullable=True)
    chars_sum = Column(Integer, default=0)
    rate = Column(DECIMAL(5, 2), default=0)
    completed = Column(Integer, default=0)
    taobao_orders = Column(String(30), default='0')
    is_delete = Column(Integer, default=0)
    file_path = Column(String(250), default='')
    user = Column(Integer, default=0)
    pdfname = Column(String(200), default='')
    lock = Column(Integer, default=0)
    pay_type = Column(String(20), default='taobao')
    out_trade_no = Column(String(100), default='')
    reduce_completed = Column(Integer, default=0)
    reduce_aigc_file = Column(String(300), default='')

    def keys(self):
        return ['order_number', 'title', 'author', 'rate', 'chars_sum', 'finished', 'create_datetime', 'is_delete',
                'user', 'pdfname', 'lock','reduce_completed','reduce_aigc_file']

    # @property
    # def rate(self):
    #     return number2string(self.similar_rate * 100) + '%'
    #
    # @property
    # def finished(self):
    #     if int(datetime.now().timestamp()) - self.create_time > 86400 * 7:
    #         return '报告已过期删除'
    #     return '正在比对' if self.completed != 1 else '已完成'
